#include "mythread.hpp"
#include <iostream>
#include <unistd.h>
#include <string>
#include <vector>
using namespace ThreadClass;
void ThreadRun(const std::string &name)
{
    int cnt = 0;
    while (cnt < 100)
    {
        std::cout << name << " Running...,cnt = " << cnt++ << std::endl;
        sleep(1);
    }
}
const int N = 5;
int main()
{
    /*---创建多线程---*/
    std::vector<Thread> threads;
    for(int i = 0;i<N;i++)
    {
        std::string name = "thread-" + std::to_string(i+1);
        threads.emplace_back(name,ThreadRun);
        sleep(1);
    }
    /*---统一启动---*/
    for(auto& tid : threads)
    {
        tid.Start();
        std::cout<<"start..."<<std::endl;
    }
    sleep(10);
    for(auto& tid : threads)
    {
        tid.Stop();
        std::cout<<"Stop done..."<<std::endl;
    }
    for(auto& tid : threads)
    {
        tid.Join();
        std::cout<<"join done..."<<std::endl;
    }
    return 0;
}
